/**
 * 
 */
package t4j.concurrency;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author sz
 *
 * create time：2013-2-26
 */
public class SleepingTask extends LiftOff{

	public void run(){
		
		try {
			while(countDown-- > 0){
				
				System.out.println(status());
				//Old-style:
				//Thread.sleep(100);
				//java se5/6-style:
				TimeUnit.MILLISECONDS.sleep(100);//这个类用的enum方法很值得研究
		
				
			}
			
		} catch (InterruptedException e) {//必须在run中被捕获，因为异常不能跨线程传播回main
			System.err.println("Interrupted");
		}
	}
	
	public static void main(String[] args) {
		ExecutorService exec = Executors.newCachedThreadPool();
		
		for(int i = 0 ;i < 5 ;i++)
			exec.execute(new SleepingTask());
		
		exec.shutdown();
	}
}
